package cn.hefan.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.hefan.domain.Task;
import cn.hefan.util.DataSourceUtils;

public class TaskDao {
//查询所有任务
	public static List<Task> selectTask() throws SQLException {
		QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from task";
		return qr.query(sql, new BeanListHandler<Task>(Task.class));
	}

	public static List<Task> selectTask(String divide) throws SQLException {
		QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from task where divide=?";
		return qr.query(sql, new BeanListHandler<Task>(Task.class),divide);
	}

	public static int addTask(Task task) throws SQLException {
		QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "insert into task(taskname,taskintd,stime,taskstatus,divide,etime) values(?,?,?,?,?,?)";
		return qr.update(sql,task.getTaskname(),task.getTaskintd(),task.getStime(),task.getTaskstatus(),task.getDivide(),task.getEtime());
	}

	public static int deletTask(String id) throws SQLException {
		QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "delete from task where id=?";
		return qr.update(sql,id);
	}

}
